package com.android.view.activity.user;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.android.model.entity.res.UserVerifierResult;
import com.android.presenter.iview.IUserVerifyView;
import com.android.util.ToastUtil;
import com.android.view.activity.base.Constants;
import com.android.view.activity.base.ToolbarBaseActivity;
import com.android.R;
import com.android.presenter.info.UserVerifyPresenter;

import butterknife.BindView;

/**
 * 重设密码
 * Created by TenFace on 2018/4/23.
 */

public class ResetPasswordActivity extends ToolbarBaseActivity implements IUserVerifyView {
    private static final String TAG = ResetPasswordActivity.class.getSimpleName();
    @BindView(R.id.etAccount)
    EditText etAccount;
    @BindView(R.id.btnSubmit)
    Button btnSubmit;

    private Context context;
    private UserVerifyPresenter userVerifyPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Constants.activityList.put(TAG, this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Constants.activityList.remove(TAG);
    }

    @Override
    protected void setContentLayout() {
        setContentView(R.layout.activity_reset_password);
    }

    @Override
    protected void initView() {
        context = this;
        int color = getResourceColor(R.color.white);
        setStatusBarColor(color, 0);
        setStatusBarMode(true);
    }

    @Override
    protected void obtainData() {
        userVerifyPresenter = new UserVerifyPresenter(this);
    }

    @Override
    protected void initEvent() {
        btnSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!TextUtils.isEmpty(etAccount.getText().toString())) {

                    userVerifyPresenter.userVerify(etAccount.getText().toString());
                } else {
                    ToastUtil.show("请输入您的账号！");
                }
            }
        });
    }

    @Override
    public void userVerifySuccess(UserVerifierResult userVerifierResult) {
        if (userVerifierResult != null) {
            SecurityVerificationActivity.actionStart(context, userVerifierResult.getPhone(),userVerifierResult.getEx55Pin());
        } else {

        }
    }

    @Override
    public void userVerifyFail(int status, String desc) {
        ToastUtil.show("用户不存在，错误代码：" + status + "，信息：" + desc);
        if (status == 10014) {
            Intent intent = new Intent();
            intent.setClass(context, RegisterActivity.class);
            startActivity(intent);
        }
    }
}
